home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / graphic / tweak16b.zip / 09TO10.CPP next >
C/C++ Source or Header  |  1993-08-04  |  3KB  |  148 lines

  1. /*
  2.     09TO10 1.0 - convert TWEAK 0.9 files to TWEAK 1.0 files
  3.  
  4.     by Robert Schmidt of Ztiff Zox Softwear, 1992-93
  5.  
  6.     For documentation, see TWEAK.DOC.
  7.  
  8.     Most of the starting definitions was taken from the TWEAK095.CPP
  9.     file included elsewhere, so comments are removed.
  10. */
  11.  
  12. #ifndef __LARGE__
  13. # ifndef __COMPACT__
  14. #  ifndef __HUGE__
  15. #   error A large data model is required!
  16. #  endif
  17. # endif
  18. #endif
  19.  
  20.  
  21. #include <stdio.h>
  22. #include <dos.h>
  23. #include <stdlib.h>
  24. #include <fstream.h>
  25. #include <io.h>
  26.  
  27. #include "Register.hpp"
  28.  
  29.  
  30. struct vgaRegisterInfo
  31.     {
  32.     char *name;
  33.     unsigned port;
  34.     unsigned char index;
  35.     };
  36.  
  37. vgaRegisterInfo table[] =
  38.     {
  39.         {"Misc. output",             0x3c2,    0x00},
  40.  
  41.         {"Horizontal total",        0x3d4,  0x00},
  42.         {"Horizontal disp. enable",    0x3d4,  0x01},
  43.         {"Horizontal blank start",    0x3d4,  0x02},
  44.         {"Horizontal blank end",    0x3d4,  0x03},
  45.         {"Horizontal retrace start",0x3d4,  0x04},
  46.         {"Horizontal retrace end",    0x3d4,  0x05},
  47.         {"Vertical total",            0x3d4,  0x06},
  48.         {"Overflow register",        0x3d4,    0x07},
  49.         {"Preset row scan",            0x3d4,    0x08},
  50.         {"Max scan line/char ht.",    0x3d4,    0x09},
  51.  
  52.         {"Vertical retrace start",    0x3d4,    0x10},
  53.         {"Vertical retrace end",    0x3d4,    0x11},
  54.         {"Vert. disp. enable end",    0x3d4,    0x12},
  55.         {"Offset/Logical width",    0x3d4,    0x13},
  56.         {"Underline location",        0x3d4,    0x14},
  57.         {"Vertical blank start",    0x3d4,    0x15},
  58.         {"Vertical blank end",        0x3d4,    0x16},
  59.         {"Mode control",            0x3d4,    0x17},
  60.  
  61.         {"Clock mode register",        0x3c4,    0x01},
  62.         {"Color plane write enable",0x3c4,    0x02},
  63.         {"Character gen. select",    0x3c4,    0x03},
  64.         {"Memory mode register",    0x3c4,    0x04},
  65.  
  66.         {"Set/reset register",        0x3ce,    0x00},
  67.         {"Set/reset enable",        0x3ce,    0x01},
  68.         {"Color compare",            0x3ce,    0x02},
  69.         {"Data rotate & function",    0x3ce,    0x03},
  70.         {"Mode register",            0x3ce,    0x05},
  71.         {"Miscellaneous register",    0x3ce,    0x06},
  72.         {"Color don't care",        0x3ce,    0x07},
  73.         {"Bit mask register",        0x3ce,    0x08},
  74.  
  75.         {"Mode control",            0x3c0,    0x10},
  76.         {"Screen border colour",    0x3c0,    0x11},
  77.         {"Color plane enable",        0x3c0,    0x12},
  78.         {"Horizontal panning",        0x3c0,    0x13},
  79.         {"Color select",            0x3c0,    0x14}
  80.     };
  81.  
  82. const registers = sizeof (table) / sizeof (vgaRegisterInfo);
  83.  
  84.  
  85. class vgaRegTable
  86.     {
  87.     unsigned char value[registers];
  88.     unsigned char selectedReg;
  89. public:
  90.     void out();
  91.     void in();
  92.     void print(unsigned char selected);
  93.     void printOne(unsigned char r, int isSelected);
  94.     unsigned char& operator [] (unsigned char n)
  95.                     { return value[n]; }
  96.     };
  97.  
  98.  
  99. // The main program starts here.
  100.  
  101. main(int argc, char **argv)
  102.     {
  103.     if (argc < 3)
  104.         {
  105.         printf("09TO10 version 1.0\n\r"
  106.                "by Robert Schmidt of Ztiff Zox Softwear 1993\n\r"
  107.                "\n\r"
  108.                "Converts TWEAK version 0.9 files to TWEAK version 1.0 files.\n\r"
  109.                "\n\r"
  110.                "Syntax:  09TO10 <oldfile> <newfile>\n\r"
  111.                );
  112.         return 0;
  113.         }
  114.  
  115.     vgaRegTable rtab;
  116.  
  117.     char *fname = argv[1];
  118.     FILE *f;
  119.     int r;
  120.  
  121.     // Open file in selected mode.
  122.     if (!(f=fopen(fname,"rb")))
  123.         {
  124.         perror(fname);
  125.         return 0;
  126.         }
  127.     // Read file:
  128.     for (r=0; r<registers; r++)
  129.         if (fread(&(rtab[r]),1,1,f) == 0)
  130.             {
  131.             perror(fname);
  132.             return 0;
  133.             }
  134.     fclose(f);
  135.  
  136.     ofstream out(argv[2], ios::trunc|ios::binary|ios::out);
  137.     Register reg;
  138.     for (r=0; r<registers; r++)
  139.         {
  140.         reg.setPort(table[r].port);
  141.         reg.setIndex(table[r].index);
  142.         reg.setValue(rtab[r]);
  143.         out << reg;
  144.         }
  145.  
  146.     return 0;
  147.     }
  148.